<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改加工库存')" />
    <!--<th:block th:include="include :: datetimepicker-css" />-->
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-inventory-edit" th:object="${processInventory}">
            <input name="id" th:field="*{id}" type="hidden">
            <!--<div class="form-group">    -->
                <!--<label class="col-sm-3 control-label is-required">品名：</label>-->
                <!--<div class="col-sm-8">-->
                    <!--<input name="productName" th:field="*{productName}" class="form-control" type="text" required>-->
                <!--</div>-->
            <!--</div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">厂家：</label>
                <div class="col-sm-8">
                    <select id="select-fact" class="form-control" th:with="type=${@dict.getType('factory_name')}"
                            onchange="chengeStatus(this.value,'other')">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{factoryName}"></option>
                        <option value="其他">其他</option>
                    </select>
                    <input id="other" placeholder="输入厂家" class="form-control" type="hidden">
                    <input name="factoryName" id="factoryName" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">原膜编号：</label>
                <div class="col-sm-8">
                    <input name="number" th:field="*{number}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">加工状态：</label>
                <div class="col-sm-8">
                    <input name="status" th:field="*{status}" class="form-control" type="hidden">
                    <input name="statusN" th:field="*{statusN}" disabled class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">材料名称：</label>
                <div class="col-sm-8">
                    <select id="select-mate" class="form-control" th:with="type=${@dict.getType('materials_name')}"
                            onchange="chengeStatus(this.value,'other_mate')">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{materialsName}"></option>
                        <option value="其他">其他</option>
                    </select>
                    <input id="other_mate" placeholder="输入材料名称" class="form-control" type="hidden">
                    <input name="materialsName" id="materialsName" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">颜色：</label>
                <div class="col-sm-8">
                    <input name="color" th:field="*{color}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">材料规格：</label>
                <div class="col-sm-3">
                    <select id="select-spec" class="form-control" th:with="type=${@dict.getType('m_specification')}"
                            onchange="chengeStatus(this.value,'other_spec')">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{mSpecification}"></option>
                        <option value="其他">其他</option>
                    </select>
                    <input id="other_spec" placeholder="输入材料规格" class="form-control" type="hidden">
                    <input name="mSpecification" id="mSpecification" class="form-control" type="hidden">
                </div>
                <label class="col-sm-2 control-label">规格单位：</label>
                <div class="col-sm-3">
                    <label class=" control-label">mm</label>
                    <!--<input name="specificationUnit" th:field="*{specificationUnit}" class="form-control" type="text">-->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">材料长度：</label>
                <div class="col-sm-7">
                    <input name="mLength" th:field="*{mLength}" class="form-control" type="number">
                </div>
                <label class=" control-label">m</label>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品重量：</label>
                <div class="col-sm-3">
                    <input name="productWeigt" th:field="*{productWeigt}" class="form-control" type="number">
                </div>
                <label class="col-sm-2 control-label">重量单位：</label>
                <div class="col-sm-3">
                    <select id="select-weigt" class="form-control" th:with="type=${@dict.getType('inventory_unit')}"
                            onchange="chengeStatus(this.value,'other_weigt')">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{weigtUnit}"></option>
                        <option value="其他">其他</option>
                    </select>
                    <input id="other_weigt" placeholder="输入重量单位" class="form-control" type="hidden">
                    <input name="weigtUnit" id="weigtUnit" class="form-control" type="hidden">
                    <!--<input name="weigtUnit" th:field="*{weigtUnit}" class="form-control" type="text">-->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">镀铝重量：</label>
                <div class="col-sm-3">
                    <input name="aluminizedWeigt" th:field="*{aluminizedWeigt}" class="form-control" type="number">
                </div>
                <label class="col-sm-2 control-label">镀铝单位：</label>
                <div class="col-sm-3">
                    <select id="select-aluminized" class="form-control" th:with="type=${@dict.getType('inventory_unit')}"
                            onchange="chengeStatus(this.value,'other_aluminized')">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{aluminizedUnit}"></option>
                        <option value="其他">其他</option>
                    </select>
                    <input id="other_aluminized" placeholder="输入镀铝单位" class="form-control" type="hidden">
                    <input name="aluminizedUnit" id="aluminizedUnit" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">入库状态：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" id="type">
                        <option value="">所有</option>
                        <option value="1">出库</option>
                        <option value="2">入库</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">来料日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input type="text" name="mDate" th:value="${#dates.format(processInventory.mDate, 'yyyy-MM-dd')}"
                               class="form-control time-input" id="startTime" placeholder="yyyy-MM-dd"/>
                        <!--<input name="mDate" th:value="${#dates.format(processInventory.mDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品要求：</label>
                <div class="col-sm-8">
                    <textarea name="productDemand" th:field="*{productDemand}" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <!--<th:block th:include="include :: datetimepicker-js" />-->
    <script th:inline="javascript">
        var prefix = ctx + "process/inventory";
        $("#form-inventory-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            //工厂
            var select = $("#select-fact").val()=="其他"?$("#other").val():$("#select-fact").val();
            $("#factoryName").val(select);
            //材料
            $("#materialsName").val(getSelectValue("mate"));
            //规格
            $("#mSpecification").val(getSelectValue("spec"));
            //重量单位
            $("#weigtUnit").val(getSelectValue("weigt"));
            //镀铝单位
            $("#aluminizedUnit").val(getSelectValue("aluminized"));
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-inventory-edit').serialize());
            }
        }
        function getSelectValue(name) {
            return $("#select-"+name).val()=="其他"?$("#other_"+name).val():$("#select-"+name).val();
        }

        // $("input[name='mDate']").datetimepicker({
        //     format: "yyyy-mm-dd",
        //     minView: "month",
        //     todayBtn: true,
        //     autoclose: true
        // });
        function chengeStatus(val,id) {
            if(val == "其他"){
                $("#"+id).attr("type","text");
            }else{
                $("#"+id).attr("type","hidden");
            }
        }
        $(function() {
            var e = [[${processInventory}]];
            var fact = [[${fact}]];
            var mate = [[${mate}]];
            var spec = [[${spec}]];
            var unit = ["kg","m²"];
            $("#type option[value= " + e.type + "]").prop("selected",true);
            //厂名
            if(fact.indexOf(e.factoryName)==-1){
                $("#select-fact option[value= '其他']").prop("selected",true);
                $("#other").attr("type","text");
                $("#other").val(e.factoryName);
            }
            //材料
            setSelectValue(mate,"mate",e.materialsName);
            // if(mate.indexOf(e.materialsName)==-1){
            //     $("#other_mate").attr("type","text");
            //     $("#other_mate").val(e.materialsName);
            // }
            //规格
            setSelectValue(spec,"spec",e.mSpecification);
            // if(spec.indexOf(e.mSpecification)==-1){
            //     $("#other_spec").attr("type","text");
            //     $("#other_spec").val(e.mSpecification);
            // }
            //重量单位
            setSelectValue(unit,"weigt",e.weigtUnit);
            //镀铝单位
            setSelectValue(unit,"aluminized",e.aluminizedUnit);
        })
        function setSelectValue(list,name,value) {
            if(list.indexOf(value)==-1){
                $("#select-"+name+" option[value= '其他']").prop("selected",true);
                $("#other_"+name).attr("type","text");
                $("#other_"+name).val(value);
            }
        }
    </script>
</body>
</html>